//
//  AppDelegate.swift
//  AppTest
//
//  Created by lete on 2020/7/16.
//  Copyright © 2020 lete. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        
        var backButtonImage = UIImage(named: "nb_back")
        backButtonImage = backButtonImage?.stretchableImage(withLeftCapWidth: 10, topCapHeight: 10)
        if #available(iOS 13.0, *) {
            let appearance = UINavigationBarAppearance()
            appearance.configureWithOpaqueBackground()
            appearance.backgroundColor = UIColor.white
            //                   appearance.shadowImage = UIImage.init(color: .white)
            //                   appearance.setBackIndicatorImage(UIImage.init(color: .white),
            //                                                    transitionMaskImage: UIImage.init(color: .white))
            appearance.titleTextAttributes = [
                NSAttributedString.Key.foregroundColor: UIColor.black
            ]
            appearance.setBackIndicatorImage(backButtonImage, transitionMaskImage: backButtonImage)
            let buttonAppearance = UIBarButtonItemAppearance()
            buttonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.black]
            appearance.buttonAppearance = buttonAppearance
            
            UINavigationBar.appearance().standardAppearance = appearance
            UINavigationBar.appearance().scrollEdgeAppearance = appearance
            UINavigationBar.appearance().compactAppearance = appearance
            UIBarButtonItem.appearance().tintColor = UIColor.black
        } else {
            UINavigationBar.appearance().barTintColor = UIColor.white
            UINavigationBar.appearance().titleTextAttributes = [
                NSAttributedString.Key.foregroundColor: UIColor.black
            ]
            UINavigationBar.appearance().tintColor = UIColor.black
            //                   UINavigationBar.appearance().shadowImage = UIImage.init(color: .white)
        }
        
        window?.backgroundColor = .white
        
        
        return true
    }
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        print(url.absoluteString)
        
        print("====>> \(url.scheme ?? "")")
        print("====>> \(url.path)")
        print("====>> \(url.host ?? "")")
        print("====>>")
        
        if url.path.count > 0{
            /// 源文件名字
            let  sourceName = url.lastPathComponent
            /// 源文件路径
            let soureUrlPath =  url.path
            
            let targartUrl = FilePathUtils.documentsDirectoryPath()
            let ulr = URL.init(string: targartUrl)?.appendingPathComponent(sourceName)
            
            
            NSData.init(contentsOf: url)
            let su =  FileManager.default.fileExists(atPath: soureUrlPath)
            let data = NSData.init(contentsOfFile: soureUrlPath)
            if FileManager.default.fileExists(atPath: ulr!.path) {
                print("-------->>>>>>>>>>  该文件已经存在")
            }
            else {
                do {
                    try FileManager.default.moveItem(atPath: soureUrlPath, toPath: ulr!.path)
//                    try FileManager.default.copyItem(atPath: soureUrlPath, toPath: ulr!.path) //FileManager.default.copyItem(at: URL.init(string: soureUrlPath)!, to:ulr!)
                    print("Success to copy file.")
                    
                } catch  {
                    print("Failed to copy file.")
                }
            }
            
        }
        
        
        
        return true
    }
    
    
    
}

